using System;
using System.IO.Packaging;
using System.IO;
using System.Workflow.ComponentModel;
using System.Text;

namespace OWA.Activities
{
	public class MarkAsFinalActivity
        : AbstractPackageActivity
	{
        static readonly string CT_CustomProperties = "application/vnd.openxmlformats-officedocument.custom-properties+xml";
        static readonly string RT_CustomProperties = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties";

        protected override System.Workflow.ComponentModel.ActivityExecutionStatus Execute(System.Workflow.ComponentModel.ActivityExecutionContext executionContext)
        {
            Package package = GetPackage();
            Uri customPropertiesPartUri =
                CreatePartUri(package, "markasfinal.xml");
            PackagePart customPropertiesPart = package.CreatePart(
                customPropertiesPartUri, CT_CustomProperties);
            package.CreateRelationship(customPropertiesPartUri,
                TargetMode.Internal, RT_CustomProperties);
            using (StreamWriter writer = new StreamWriter(
                customPropertiesPart.GetStream(FileMode.Create, FileAccess.ReadWrite),
                Encoding.Unicode))
            {
                writer.Write(Properties.Resources.MarkAsFinal);
            }
            return ActivityExecutionStatus.Closed;
        }
	}
}
